package com.bj.disc.base

import android.app.Activity
import android.view.Gravity
import android.view.WindowManager
import android.view.animation.Animation
import android.view.animation.RotateAnimation
import android.widget.ImageView
import android.widget.TextView
import com.ai3d.rfid.R
import com.ai3d.rfid.base.dialog.BaseDialog


/**
 * @ProjectName : Kolb
 * @Author : weijinsong
 * @Time : 2023/2/6 9:55
 * @Description : 文件描述
 */
class StatusDialog(var activity: Activity, var status: Int) :
    BaseDialog(activity, R.style.AlertDialogThemeNoBackground) {
    companion object {
        const val NETWORK_ANOMALY = 1
        const val SYNCHRONOUS_RISE = 2
        const val SYNCHRONIZATION_SUCCEEDED = 3
    }

    var ivIcon: ImageView? = null
    var tvName: TextView? = null

    override fun initView() {
        val layoutParams = window!!.attributes
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT
        layoutParams.gravity = Gravity.CENTER
        window?.attributes = layoutParams
        setCanceledOnTouchOutside(true)

        ivIcon = findViewById(R.id.ivIcon)
        tvName = findViewById(R.id.tvName)
    }

    override fun initEvent() {
//        var progressDialog = activity?.let { StatusDialog(it, StatusDialog.SYNCHRONOUS_RISE) }
//        progressDialog?.show()

    }

    override fun initData() {
        when (status) {
            NETWORK_ANOMALY -> {
                ivIcon?.setImageResource(R.mipmap.network_anomaly)
                //tvName?.setText(R.string.network_anomaly)
            }
            SYNCHRONOUS_RISE -> {
                ivIcon?.setImageResource(R.mipmap.synchronous_rise)
               // tvName?.setText(R.string.synchronous_rise)
                // 创建旋转的动画对象
                val ta = RotateAnimation(
                    0f,
                    360f,
                    RotateAnimation.RELATIVE_TO_SELF,
                    0.5f,
                    RotateAnimation.RELATIVE_TO_SELF,
                    0.5f
                )

                // 设置动画播放的时间
                ta.duration = 2000
                ta.repeatCount = Animation.INFINITE
                // 开始播放动画
                ivIcon?.startAnimation(ta)
            }
            SYNCHRONIZATION_SUCCEEDED -> {
                ivIcon?.setImageResource(R.mipmap.synchronization_succeeded)
               // tvName?.setText(R.string.synchronization_succeeded)
            }
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_status
    }

    override fun getAnimId(): Int {
        return -1
    }

    override fun dismiss() {
        super.dismiss()

    }
}